package com.zen.lon.open.proxy;

import com.zen.lon.open.remote.utils.ClassProviderUtils;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 代理工厂，用于创建代理
 *
 * @author ZonLen since on 2021/7/12 下午1:28
 */

public final class ProxyAgentClassManager {

  private static final Map<String, Class<?>> proxy_class_cache = new ConcurrentHashMap<>();

  public static void add(String className) {
    proxy_class_cache.putIfAbsent(className, ClassProviderUtils.forName(className));
  }

  public static Class<?> getClassByName(String className) {
    return proxy_class_cache.computeIfAbsent(className, ClassProviderUtils::forName);
  }

//  public static <T> List<Class<? extends T>> getSubInstanceClassByType(Class<T> tClass) {
//    return proxy_class_cache.values().stream().filter(tClass::isAssignableFrom)
//        .filter(subClass -> !subClass.isInterface()).map(subClass -> (Class<? extends T>) subClass)
//        .distinct().collect(Collectors.toList());
//  }
}
